//手写 Object.create  将传入的对象作为原型
function create(obj) {
  function F() {}
  F.prototype = obj;
  return new F();
}
// 手写instanceof
function myInstanceof(left, right) {
  let proto = Object.getPrototypeOf(left),
    prototype = right.prototype;

  while (true) {
    if (!proto) return false;
    if (proto === prototype) return true;
    proto = Object.getPrototypeOf(proto);
  }
}
//手写new操作符   objectFactory(构造函数，初始化参数)
function objectFactory() {
  let newObject = null;
  let constructor = Array.prototype.shift.call(arguments);
  let result = null;
  if (typeof constructor !== "function") {
    console.log("type error");
    return;
  }
  newObject = Object.create(constructor.prototype);
  result = constructor.apply(newObject, arguments);
  //&&遇到假的就返回  ||遇到真就返回
  let flag =result && (typeof result === "object" || typeof result === "function");
  return flag ? result :newObject
}



